package com.novoda.runbuddy.view;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.novoda.runbuddy.R;
import com.novoda.runbuddy.controller.IDayController;

public class RunEntryView extends LinearLayout {

	protected static final int	MAPOFJOG	= 3333;
	private TextView			miles;
	private TextView			heading_jogname;
	private TextView			timerun;
	private ImageView			mapLinkIcon;
	private long				jogStartTime;
	private IDayController		dayOfJogControllerImpl;

	public RunEntryView(Activity context, TextView miles, TextView heading_jogname, TextView timerun, long jogStartTime,
			IDayController dayOfJogDetailsControllerImpl) {
		super(context);

		this.setOrientation(VERTICAL);
		this.miles = miles;
		this.heading_jogname = heading_jogname;
		this.timerun = timerun;
		this.setPadding(0, 8, 0, 12);
		this.jogStartTime = jogStartTime;
		this.dayOfJogControllerImpl = dayOfJogDetailsControllerImpl;

		String headingBeforeAmmend = heading_jogname.getText().toString();
		heading_jogname.setText("Route: " + headingBeforeAmmend);
		addView(heading_jogname, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

		String textBeforeAmmend = timerun.getText().toString();
		timerun.setText("Time: " + textBeforeAmmend);
		addView(timerun, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

		String milesBeforeAmmend = miles.getText().toString();
		miles.setText("Distance: " + milesBeforeAmmend);
		addView(miles, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

		mapLinkIcon = new ImageView(context);
		mapLinkIcon.setImageResource(R.drawable.map);
		mapLinkIcon.setAdjustViewBounds(true);
		mapLinkIcon.setOnClickListener(mapClick);

		addView(mapLinkIcon, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

	}

	public TextView getMiles() {
		return miles;
	}

	public void setMiles(String text) {
		this.miles.setText(text);
	}

	public TextView getHeading_jogname() {
		return heading_jogname;
	}

	public void setHeading_jogname(String text) {
		this.heading_jogname.setText(text);
	}

	public TextView getTimerun() {
		return timerun;
	}

	public void setTimerun(String text) {
		this.timerun.setText(text);
	}

	private OnClickListener	mapClick	= new OnClickListener()
										{

											public void onClick(View arg0) {
												dayOfJogControllerImpl.openMapViewForRuns(jogStartTime);
											}
										};

}
